import axios from "axios";

const axiosEl = axios.create({
    baseURL:'http://localhost:8081',
    timeout:5000
})


// 请求拦截
axiosEl.interceptors.request.use((config)=>{
    let token = localStorage.getItem('token');
    config.headers.Authorization = token ;
     return config;
})

//  响应的拦截
axiosEl.interceptors.response.use((res)=>{
    return res.data;
},(err)=>{
     
    if(err.response && err.response.status) {
        switch(err.response.status){
            case  404:
                console.log('接口错误');
                break;
            case 500:
                console.log('服务端错误'); 
                break;
            case 403:
                console.log('跳转到登录');
                
                break;
            case  401:
                console.log('无效的token'); 
                 
                break;
            default:
                console.log('错误异常');   
                break;
        }
    }

    return false;
})

export default axiosEl;